<script setup lang='ts'>
  import { reactive } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getSummaries } from '@/utils'
  import { getPlayEndTime, getDateArray } from '@/utils'
  import xmDatePicker from '@/components/xmDatePicker/index.vue';
  import Pagination from "@/components/Pagination/index.vue";
  const $emit = defineEmits(['updateList'])
  const action = reactive({
    dialogFormVisible:false,
    disabled:true,
    total:0,
    timeObj:getPlayEndTime(getDateArray('ymd')),
    list:[] as any[],
  })
  const listQuery = reactive({
    page: 1,
    limit: 20,
    date_st:0,
    date_ed:0,
  })
  const handleSerach = ()=>{
    listQuery.page = 1
    action.list = []
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const { playTime:date_st, endTime:date_ed } = action.timeObj
    const res = await statisticsApi.statisticsList({
      ...listQuery,
      date_st,
      date_ed
    })
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
  }
  const openDialog = async(query:any = {})=> {
    await getList()
    action.dialogFormVisible = true
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-dialog
    top="5vh"
    class="xm-dialog"
    v-model="action.dialogFormVisible"
    :close-on-click-modal="action.disabled"
    :show-close="action.disabled"
    :close-on-press-escape="action.disabled"
    width="75%"
    title="周星统计">
    <div class="xm-headTab">
      <div class="labelBox">
        <xmDatePicker type="daterange" v-model:timeval="action.timeObj" />
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-TableCenter"
      :data="action.list"
      show-summary
      height="460"
      :summary-method="((param:any)=>getSummaries(param,[1,2]))"
      border>
      <el-table-column width="80" prop="id" label="ID" />
      <el-table-column width="180" prop="created_at" label="创建日期" />
      <el-table-column label="礼物一">
        <el-table-column width="80" prop="gift1" label="礼物ID" />
        <el-table-column width="100" prop="giftName1" label="礼物名称" />
        <el-table-column width="100" prop="giftNum1" label="房间内送出礼物个数" />
        <el-table-column width="100" prop="userNum1" label="送礼人数" />
        <el-table-column width="100" prop="totalNum1" label="钻石数" />
      </el-table-column>
      <el-table-column label="礼物二">
        <el-table-column width="80" prop="gift2" label="礼物ID" />
        <el-table-column width="100" prop="giftName2" label="礼物名称" />
        <el-table-column width="100" prop="giftNum2" label="房间内送出礼物个数" />
        <el-table-column width="100" prop="userNum2" label="送礼人数" />
        <el-table-column width="100" prop="totalNum2" label="钻石数" />
      </el-table-column>
      <el-table-column label="礼物三">
        <el-table-column width="80" prop="gift3" label="礼物ID" />
        <el-table-column width="100" prop="giftName3" label="礼物名称" />
        <el-table-column width="100" prop="giftNum3" label="房间内送出礼物个数" />
        <el-table-column width="100" prop="userNum3" label="送礼人数" />
        <el-table-column width="100" prop="totalNum3" label="钻石数" />
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    </el-dialog>
  </div>
</template>